<?php
namespace Api\Controller;
use Think\Controller;

class UserController extends CommonController
{

    //登录功能
    public function login()
    {
        $username = I('post.username');
        $password = I('post.password');

        //$checkcode = I('post.checkcode');
        //检查验证码是否正确
        //$obj = new \Think\Verify();

        // if (!$obj->check($checkcode)) {
        //     $this->ajaxReturn(array('status' => 0, 'msg' => '验证码错误'));
        // }

        //实例化模型对象，调用方法入库
        $model = D('UserList');
        $res = $model->login($username, $password);
        if (!$res) {
            $this->ajaxReturn(array('code' => 201, 'msg' =>'no' ),'json');
        }
        $this->ajaxReturn(array('code' => 200, 'msg' => 'ok'),'json');

    }

    //退出功能
    public function logout()
    {
        session('user', null);
        session('user_id', null);
        $this->redirect('/');
    }
}